var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

export default function(email:string, subject:string, text:string) {
    var transporter = nodemailer.createTransport(smtpTransport({
        host: 'smtp.qq.com',
        secure: true, 
        secureConnection: true, 
        port: 465, 
        auth: {
            user: '1242598374@qq.com',
            pass: 'eiuhjvddwzwgfgbe'//授权码  

        }
    }));
    var mailOptions = {
        from: '1242598374@qq.com',  
        to: email,
        subject: subject,  
        text: text,
    }; 
    var result = {
        httpCode: 200,
        message: '发送成功!',
        data: [],
    }
    try {
        transporter.sendMail(mailOptions, function (err:string, info:string) {
            if (err) {
                result.httpCode = 500;
                result.message = err;
                console.log(result);
                return;
            }
            console.log(result);
        });
    } catch (err) {
        result.httpCode = 500;
        result.message = err;
        console.log(result);
    }
    transporter.close(); 

}